package com.lt.lumentracks.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lt.lumentracks.entity.po.Post;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 帖子主表 Mapper 接口
 * </p>
 *
 * @author swl
 * @since 2025-07-11
 */
public interface PostMapper extends BaseMapper<Post> {

    // 新增帖子时，往对应的关联表中批量插入该帖子关联的标签id
    void insert_PostTag(@Param("postId") Integer postId,
                        @Param("tagIdList") List<Integer> tagIdList);

    // 新增帖子时，往对应的关联表中批量插入该帖子关联的话题id
    void insert_PostTopic(@Param("postId")Integer postId,
                          @Param("topicIdList") List<Integer> topicIdList);

    // 新增帖子时，往对应的关联表中批量插入该帖子关联的图片id
    void insert_PostImage(@Param("postId") Integer id,
                          @Param("imageUrlList")List<String> imageUrlList);

    // 根据用户id查询该用户所关注的人的帖子
    @Select("select p.* " +
            "from post p " +
            "    join follow f on p.user_id = f.follow_user_id " +
            "    join user u on u.id = f.follow_user_id " +
            "where f.user_id = #{userId}")
    IPage<Post> listByMyFollowing(@Param("userId")Integer userId, Page<Post> p);


    // 根据标签id列表查询帖子，精确匹配标签，不多不少
    IPage<Post> getPostsListByTagIds_exact(Page<Post> p,
                                           @Param("tagIdList") List<Integer> tagIdList,
                                           @Param("listLen") int listLen);


    // 根据话题ID列表查询帖子
    List<Post> getPostsByTopicIds(Page<Post> p_param,
                                  @Param("topicIdList") List<Integer> topicIdList);

    int getTopicPostsCount(List<Integer> topicIdList);


    // 根据标签id列表查询帖子
    List<Post> getPostsListByTagIds(Page<Post> p_param,
                                    @Param("tagIdList") List<Integer> tagIdList);

    int getTagPostsCount(@Param("tagIdList") List<Integer> tagIdList);
}
